NexusPi Git Node
WebSocketConsole.h f0aee0671e84b627f90883c0f1fca8f0d4dbc9da (f0aee067) Text, 2.33 KB
T8b949e// WebSocketConsole — KISS↔WebSocket bridge for the embedded web console.
T8b949e//
T8b949e// Sits between WebSocketServer (RFC 6455 frames) and the firmware's KISS
T8b949e// I/O. One WebSocket binary frame == one KISS frame on the wire, including
T8b949e// the leading and trailing FEND markers.
T8b949e//
T8b949e// Outbound (firmware → browser):
T8b949e// * Hook into Utilities.h::serial_write() via ws_console::on_serial_write(b).
T8b949e// * We buffer bytes between KISS frame boundaries (FEND) and emit one
T8b949e// binary WebSocket frame per complete KISS frame.
T8b949e//
T8b949e// Inbound (browser → firmware):
T8b949e// * Each binary WS frame is treated as one KISS frame and pushed into
T8b949e// serialFIFO; serial_poll() in RNode_Firmware.ino then parses it.
T8b949e// * Text frames are not currently used (KISS is binary). They're
T8b949e// accepted by WebSocketServer but ignored here.
T8b949e//
T8b949e// Single-client by design — matches Remote.h and TCPHostInterface.h.
Tff7b72#Tff7b72ifndef WEBSOCKET_CONSOLE_H
Tff7b72#Tff7b72define WEBSOCKET_CONSOLE_H
Tff7b72#Tff7b72if defined(ENABLE_WEBSOCKETS) && __has_include(<WiFi.h>)
Tff7b72#Tff7b72include T8b949e<cstdint>
Te6edf3namespace Te6edf3ws_console Tb4b4b4{
T8b949e// Initialize on the given TCP port (typically 81 alongside HTTP on 80).
T8b949e// bind_public is honored only on native (Portduino) — false binds the
T8b949e// listening socket to 127.0.0.1, true to 0.0.0.0. ESP32 always binds
T8b949e// 0.0.0.0 regardless (the console is served over WiFi AP).
T8b949e// Safe to call multiple times — second and subsequent calls no-op.
Tffa657void Td2a8ffinitTb4b4b4(Tffa657uint16_t Te6edf3portTb4b4b4, Tffa657bool Te6edf3bind_public Tff7b72= Tffa657falseTb4b4b4)Tb4b4b4;
T8b949e// Drive the underlying WebSocketServer. Call once per main-loop tick.
T8b949e// Non-blocking.
Tffa657void Td2a8ffserviceTb4b4b4(Tb4b4b4)Tb4b4b4;
T8b949e// Outbound tap from serial_write(). Buffers bytes between KISS FEND
T8b949e// markers and flushes a complete KISS frame as a single WS binary frame
T8b949e// when a client is attached. Bytes are dropped on the floor when no
T8b949e// client is attached — same behavior as the existing wifi/native TCP
T8b949e// transports.
Tffa657void Td2a8ffon_serial_writeTb4b4b4(Tffa657uint8_t Te6edf3byteTb4b4b4)Tb4b4b4;
T8b949e// True when a client is connected and the WS handshake is complete.
Tffa657bool Td2a8ffclient_attachedTb4b4b4(Tb4b4b4)Tb4b4b4;
T8b949e// Tear down the underlying WebSocketServer (close listener, drop client,
T8b949e// delete the singleton). Called from the native deferred-reboot path so
T8b949e// the re-exec'd process can re-bind the same port. Idempotent.
Tffa657void Td2a8ffshutdownTb4b4b4(Tb4b4b4)Tb4b4b4;
Tb4b4b4} T8b949e// namespace ws_console
Tff7b72#Tff7b72endif T8b949e// ENABLE_WEBSOCKETS && __has_include(<WiFi.h>)
Tff7b72#Tff7b72endif T8b949e// WEBSOCKET_CONSOLE_H
Served by rngit 1.5.2 - Generated in 0.01s